<?php
	require_once (dirname(__FILE__)."/../config/Config.inc");
	require_once (dirname(__FILE__)."/../config/api.inc");
	$result['status'] = '0';
	
	$method = getParam('m','get');
	
	if($method == 'answer')
	{
		$phone =  getParam('phone','get');
		$name =  getParam('name','get');
		$answer =  getParam('answer','get');
		if(empty($phone))
		{
			$result['msg'] = '请输入手机号';
			echoJSON($result);
			exit;
		}
		
		if(empty($answer))
		{
			$result['msg'] = '请选择问题答案';
			echoJSON($result);
			exit;
		}
		
		unset($query);
		$query['phone'] = $phone;
		$info = _SqlTool::getInfo('huodong_answer', $query);
		
		if(!empty($info))
		{
			$result['msg'] = '已经参与过';
			echoJSON($result);
			exit;
		}
		
		$list = explode(',', $answer);
		
		unset($Useranswers);
		
		foreach ($list as $key => $value)
		{
			$Useranswers[(string)($key+1)] = $value;
		}
		
		$SysAnswer["1"] = 'A';
		$SysAnswer["2"] = 'A';
		$SysAnswer["3"] = 'A';
		$SysAnswer["4"] = 'A';
		$SysAnswer["5"] = 'C';
		$SysAnswer["6"] = 'A';
		
		if(count($Useranswers) != 6)
		{
			$result['msg'] = '有未完成的答题';
			echoJSON($result);
			exit;
		}
		
		$jisuan = array_intersect_assoc($Useranswers, $SysAnswer);
		
		$score = count($jisuan) * 10;

		$answer =  getParam('answer','get');
		$data['phone'] = $phone;
		$data['name'] = $name;
		$data['answer'] = $answer;
		$data['score'] = $score;
		$data['addtime'] = time();
		$res = _SqlTool::addInfo('huodong_answer', $data);
		
		if(!empty($res))
		{
			$result['status'] = '1';
			$result['msg'] = '提交成功';
			$result['score'] = $score;
		}
		else
		{
			$result['msg'] = '提交失败';
		}
	}

echoJSON($result);
	
	
